"""
极坐标图
对应参数方程曲线，主要是二维
波束图
"""

import numpy as np 
import matplotlib.pyplot as plt

alpha11 = np.array([0, -1, -1/2, -1/np.sqrt(2)])
mcolor = ['red', 'brown', 'black', 'blue']
lwidth = ['solid', 'dashdot', 'dotted', 'dashed']
f = 1000
d = 0.02
c = 340.0
tao0 = d/c
theta = np.linspace(0, 360, 361, endpoint=True)/180*np.pi
Bf = np.zeros((len(theta), 4), dtype=np.complex)
for ii in range(4):
    for i in range(len(theta)):
        Bf[i, ii] = 1j/((alpha11[ii]-1)*tao0*f)*(1-np.exp(-1j*2*np.pi*f*tao0*(np.cos(theta[i])-alpha11[ii])))   

fig = plt.figure()
ax1 = fig.add_subplot(111, projection='polar')
ax1.plot(theta, 10*np.log10(np.abs(Bf[:, 2])/np.max(np.abs(Bf[:, 2]))+0.001), linestyle=lwidth[0], linewidth=1.5, color=mcolor[0])
# ax2.set_theta_zero_location('N')
ax1.set_rlim(-20, 0) # 极坐标系的两个参数
ax1.set_rlabel_position(150) # 把标签放在150度的刻度线上
ax1.set_thetagrids(np.arange(0.0, 360.0, 30.0)) # 设置角度间隔
ax1.set_rgrids([0, -3, -6, -9, -12, -15, -18], ['0dB', '-3dB', '-6dB', '-9dB', '-12dB', '-15dB', '-18dB'], fontsize=7)
ax1.grid(True, linestyle=lwidth[2], color='gray', lw=0.6) # 一般网格线以虚线，灰色，比较细为主
ax1.set_title('Fig. 1 beam pattern', y=-0.13) # 把标题放在图下面
plt.show()

